import requests
from src.utils.Enums.models import HTTPMethod
from src.utils.abstract_client import AbstractHTTPClient

class RequestsAdapter(AbstractHTTPClient):
    """适配器：将 requests 库适配到抽象接口"""
    def __init__(self, base_url: str):
        self.base_url = base_url
        self.session = requests.Session()

    def request(self, method: HTTPMethod, endpoint: str, **kwargs) -> dict:
        url = f"{self.base_url}/{endpoint.lstrip('/')}"
        response = self.session.request(
            method.name,  # 使用枚举值转换为字符串（如 'GET'）
            url,
            **kwargs
        )
        response.raise_for_status()
        return response.json()